/**
 * Created by lf on 17-1-1.
 */
$(document).ready(function () {
    var url = window.location.href;
    var host = 'http://120.55.161.117:8080';
    var area_id = 1;
    var url1 = '/portal/article/detail/content'; //文章详情
    var url2 = '/portal/article/bind/series'; //绑定车型信息，以及关联车型
    var url3 = '/portal/article/author/producer'; //当文章由经销商创建时，经销商信息
    var data = url.split('?');
    if(data[1]){
        var article_id = data[1].split('=')[1];
    }else{
        article_id = null;
    }
    $.ajax({
        url: host + url1,
        type: 'get',
        async: true,
        dataType: 'json',
        data: {"article_id": article_id},
        success: function (data) {
            if(data['res']=='success') {
                var t = "<h2>" + data['title'] + "</h2><br>";
                t += data['content'];
                $('#mainArticle').html(t);
                $('#tinyTitle').text(data['title']);
                var _url = "carPic.htm?id=" + data['id'];
                $('#tinyTitle').parent().attr({href: _url});
                if(data['s_ex']){
                    bind_series_exist(data['id'], host, url2);
                }
                // if(data['is_producer']){
                //
                // }
            }
        }
    });

});

function bind_series_exist(article_id,host, url) {
    $.ajax({
        url: host + url,
        type: 'get',
        async: true,
        dataType: 'json',
        data: {"article_id": article_id},
        success:function (data) {
            if(data['res']=='success'){
                var t ="<a><img src='"+ host + data['b_logo'] + "'></a><h1><a href='#'>"+ data['series'] +"</a></h1><span>全部在售</span>";
                if(data['y_list']){
                    for(var i=0; i<data['y_list'].length;i++){
                        t += "<p><a href='#'> " + data['y_list'][i] + "</a></p>";
                    }
                }
                $('#seriesRecommend').html(t);
                $('#seriesRecommend').show();
                if(data['s_list']){
                    for(var j=0;j<data['s_list'].length;j++){
                        var txt = "<a href='#'><img src='" + host + data['s_list'][j]['pic'] + "'><p>" + data['s_list'][j]['name'] + "</p></a>";
                        $('#relatedSeries').children().eq(j).html(txt);
                    }
                    $('#relatedSeriesLabel').show();
                    $('#relatedSeries').show();
                }
            }
        }
    });
}
